/*
 * TestBSharpTree.cpp
 *
 *  Created on: 30/10/2009
 *      Author: christian
 */

#include <iostream>
#include "../Externa/Clave.h"
#include "../Externa/Dato.h"
#include "../Strategies/Index/IndexStrategy.h"
#include "Alumno.h"
#include "../StorageResourceFactory.h"

using namespace std;


class TestBSharpTree {

	StorageResourceFactory *storageResourceFactory;
	IndexStrategy *indexStragegy;

public:

	void Setup () {

		const string nombre = "TestBSharp.txt";
		storageResourceFactory = new StorageResourceFactory();
		storageResourceFactory->createStorageTextResource(nombre);
		indexStragegy = storageResourceFactory->getStorageResource()->getIndexStategy();

	}

	void Terminar () {
		delete storageResourceFactory;

		cout << "El test de TestBSharpTree se completo"<< endl;
	}

	void insertarClave () {
		Clave *clave = new Clave("miClave", new Alumno());
		clave->setClave("valor2");
		Clave *clave2 = new Clave("otraClave", new Alumno());
		clave2->setClave("valor1");
		Clave *clave3 = new Clave("laClave", new Alumno());
		clave3->setClave("valor3");
		Clave *clave4 = new Clave("laClave", new Alumno());
		clave4->setClave("valor5");
		Clave *clave5 = new Clave("laClave", new Alumno());
		clave5->setClave("valor4");
		Clave *clave6 = new Clave("miClave", new Alumno());
		clave6->setClave("valor1");

		if (!indexStragegy->checkUniqueness(clave, new Alumno())){
			cout<<"Unicidad... Correcta"<<endl;

			indexStragegy->updateIndex(2, clave, new Alumno());
			indexStragegy->updateIndex(3, clave2, new Alumno());
			cout<<"paso"<<endl;
			//indexStragegy->deleteKey(clave2);
			//cout<<"clave2 borrada"<<endl;
			/*indexStragegy->updateIndex(4, clave3, new Alumno());
			cout<<"paso"<<endl;
			indexStragegy->updateIndex(5, clave4, new Alumno());*/
			//indexStragegy->updateIndex(6, clave5, new Alumno());

			if (indexStragegy->getStorageReferenceByKey(clave6) == 2){
				cout<<"Insercion... Correcta"<<endl;
			}
			else{
				cout<<"Insercion... Incorrecta"<<endl;
			}
		}
		else
			cout<<"Unicidad... Incorrecta"<<endl;
		//}
	}

	void Run() {
		Setup();
		insertarClave();
		Terminar();
	}

};
